﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Common;
using DotNet.Data.Factory;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace DotNet.Data
{
	public class Tab_CaseClassDal
	{
		IDBHelp db = DBHelp.Create();
		 Hashtable htSyn = Hashtable.Synchronized(new Hashtable());
		StringBuilder strSql = new StringBuilder();

		#region 是否存在该记录
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		/// <param name="CaseClassID">标识列ID</param>
		public bool Exists(int CaseClassID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select count(1) from [Tab_CaseClass] where CaseClassID=@caseclassid ");
			htSyn.Add("@caseclassid", CaseClassID);
			return db.IsExists(strSql.ToString(), htSyn);
		}
		#endregion

		#region 得到该表数据列表
		/// <summary>
		/// 得到该表数据列表
		/// </summary>
		public IList<Tab_CaseClass> GetModel()
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
            strSql.Append("Select [CaseClassID],[CaseClassFID],[CaseClassDescription],[CaseClassKey],[CaseClassDate],[CaseClassName],[CaseClassInfo],[CaseClassTitle] FROM [Tab_CaseClass] where [CaseClassFID]=0");
			return getTab_CaseClassBySql(strSql.ToString());
		}
		#endregion

		#region 根据标识列查询实体
		/// <summary>
		/// 根据标识列查询实体
		/// </summary>
		/// <param name="CaseClassID">标识列ID</param>
		/// <returns></returns>
		public Tab_CaseClass GetModel(int caseclassid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select [CaseClassID],[CaseClassFID],[CaseClassDescription],[CaseClassKey],[CaseClassDate],[CaseClassName],[CaseClassInfo],[CaseClassTitle] FROM [Tab_CaseClass]");
			strSql.Append(" where CaseClassID=@caseclassid ");
			htSyn.Add("@caseclassid", caseclassid);
			DataTable dt = db.GetDataTable(strSql.ToString(), htSyn);
			Tab_CaseClass tab_caseclassModel = new Tab_CaseClass();
			if (dt.Rows.Count > 0)
			{
				tab_caseclassModel.caseClassFID=dt.Rows[0]["CaseClassFID"].ToString();
				tab_caseclassModel.caseClassDescription=dt.Rows[0]["CaseClassDescription"].ToString();
				tab_caseclassModel.caseClassKey=dt.Rows[0]["CaseClassKey"].ToString();
				tab_caseclassModel.caseClassDate=dt.Rows[0]["CaseClassDate"].ToString();
				tab_caseclassModel.caseClassName=dt.Rows[0]["CaseClassName"].ToString();
				tab_caseclassModel.caseClassInfo=dt.Rows[0]["CaseClassInfo"].ToString();
				tab_caseclassModel.caseClassTitle=dt.Rows[0]["CaseClassTitle"].ToString();
			}
			return tab_caseclassModel;
		}
		#endregion

        #region 根据方案父类别ID查询列表
        public IList<Tab_CaseClass> GetModelByFID(int caseClassFID) 
        {
            htSyn.Clear();
            strSql.Remove(0, strSql.Length);
            strSql.Append("Select [CaseClassID],[CaseClassFID],[CaseClassDescription],[CaseClassKey],[CaseClassDate],[CaseClassName],[CaseClassInfo],[CaseClassTitle] FROM [Tab_CaseClass] where [CaseClassFID]=@CaseClassFID");
            htSyn.Add("@CaseClassFID", caseClassFID);
            return getTab_CaseClassBySql(strSql.ToString(), htSyn);
        }       
        #endregion

        #region 修改信息
        /// <summary>
		/// 修改信息
		/// </summary>
		/// <param name="Tab_CaseClass">实体</param>
		/// <returns></returns>
		public bool Update(Tab_CaseClass tab_caseclassModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("update [Tab_CaseClass] set ");
			strSql.Append("[CaseClassFID]=@caseclassfid,");
			strSql.Append("[CaseClassDescription]=@caseclassdescription,");
			strSql.Append("[CaseClassKey]=@caseclasskey,");
			strSql.Append("[CaseClassDate]=@caseclassdate,");
			strSql.Append("[CaseClassName]=@caseclassname,");
			strSql.Append("[CaseClassInfo]=@caseclassinfo,");
			strSql.Append("[CaseClassTitle]=@caseclasstitle");

			strSql.Append(" where CaseClassID=@caseclassid ");
			htSyn.Add("@caseclassid", tab_caseclassModel.caseClassID);
			htSyn.Add("@caseclassfid", tab_caseclassModel.caseClassFID);
			htSyn.Add("@caseclassdescription", tab_caseclassModel.caseClassDescription);
			htSyn.Add("@caseclasskey", tab_caseclassModel.caseClassKey);
			htSyn.Add("@caseclassdate", tab_caseclassModel.caseClassDate);
			htSyn.Add("@caseclassname", tab_caseclassModel.caseClassName);
			htSyn.Add("@caseclassinfo", tab_caseclassModel.caseClassInfo);
			htSyn.Add("@caseclasstitle", tab_caseclassModel.caseClassTitle);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 删除信息
		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="CaseClassID">标识列ID</param>
		/// <returns></returns>
		public bool Delete(int CaseClassID)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("delete from [Tab_CaseClass] where CaseClassID=@caseclassid");
			htSyn.Add("caseclassid", CaseClassID);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 添加信息
		/// <summary>
		/// 添加信息
		/// </summary>
		/// <param name="Tab_CaseClass">实体</param>
		/// <returns></returns>
		public bool Insert(Tab_CaseClass tab_caseclassModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("insert into [Tab_CaseClass]([CaseClassFID],[CaseClassDescription],[CaseClassKey],[CaseClassDate],[CaseClassName],[CaseClassInfo],[CaseClassTitle]) values (@caseclassfid,@caseclassdescription,@caseclasskey,@caseclassdate,@caseclassname,@caseclassinfo,@caseclasstitle)");
			htSyn.Add("@caseclassfid", tab_caseclassModel.caseClassFID);
			htSyn.Add("@caseclassdescription", tab_caseclassModel.caseClassDescription);
			htSyn.Add("@caseclasskey", tab_caseclassModel.caseClassKey);
			htSyn.Add("@caseclassdate", tab_caseclassModel.caseClassDate);
			htSyn.Add("@caseclassname", tab_caseclassModel.caseClassName);
			htSyn.Add("@caseclassinfo", tab_caseclassModel.caseClassInfo);
			htSyn.Add("@caseclasstitle", tab_caseclassModel.caseClassTitle);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 根据SQL语句获取集合
		/// <summary>
		///根据SQL语句获取集合
		/// </summary>
		/// <param name="strSql">sql语句</param>
		public IList<Tab_CaseClass> getTab_CaseClassBySql(string strSql)
		{
			IList<Tab_CaseClass> list = new List<Tab_CaseClass>();
			DataTable dt = db.GetDataTable(strSql);
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					Tab_CaseClass tab_caseclassModel = new Tab_CaseClass();
					tab_caseclassModel.caseClassID= Convert.ToInt32(dr["CaseClassID"]);
					tab_caseclassModel.caseClassFID=dr["CaseClassFID"].ToString();
					tab_caseclassModel.caseClassDescription=dr["CaseClassDescription"].ToString();
					tab_caseclassModel.caseClassKey=dr["CaseClassKey"].ToString();
					tab_caseclassModel.caseClassDate=dr["CaseClassDate"].ToString();
					tab_caseclassModel.caseClassName=dr["CaseClassName"].ToString();
					tab_caseclassModel.caseClassInfo=dr["CaseClassInfo"].ToString();
					tab_caseclassModel.caseClassTitle=dr["CaseClassTitle"].ToString();
					list.Add(tab_caseclassModel);
				}
			}
			return list;
		}
		#endregion

        #region 根据SQL语句获取集合
        /// <summary>
        ///根据SQL语句获取集合
        /// </summary>
        /// <param name="strSql">sql语句</param>
        /// <param name="ht">参数</param>
        public IList<Tab_CaseClass> getTab_CaseClassBySql(string strSql,Hashtable ht)
        {
            IList<Tab_CaseClass> list = new List<Tab_CaseClass>();
            DataTable dt = db.GetDataTable(strSql,ht);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    Tab_CaseClass tab_caseclassModel = new Tab_CaseClass();
                    tab_caseclassModel.caseClassID = Convert.ToInt32(dr["CaseClassID"]);
                    tab_caseclassModel.caseClassFID = dr["CaseClassFID"].ToString();
                    tab_caseclassModel.caseClassDescription = dr["CaseClassDescription"].ToString();
                    tab_caseclassModel.caseClassKey = dr["CaseClassKey"].ToString();
                    tab_caseclassModel.caseClassDate = dr["CaseClassDate"].ToString();
                    tab_caseclassModel.caseClassName = dr["CaseClassName"].ToString();
                    tab_caseclassModel.caseClassInfo = dr["CaseClassInfo"].ToString();
                    tab_caseclassModel.caseClassTitle = dr["CaseClassTitle"].ToString();
                    list.Add(tab_caseclassModel);
                }
            }
            return list;
        }
        #endregion
	}
}
